package com.ywt.cda.domain;

import java.io.Serializable;
import java.util.List;

import com.ywt.cda.enums.FunctionsEnum;

public class UserAgent implements Serializable
{

	private static final long serialVersionUID = 1025569259439372180L;

	private String loginName;
	private String userType;
	private String appId;
	private List<FunctionsEnum> functions;
	public static final String USER_AGENT_IN_REQUEST = "userAgent";
	
	public String getAppId() {
		return appId;
	}
	public void setAppId(String appId) {
		this.appId = appId;
	}
	public String getLoginName()
	{
		return loginName;
	}
	public void setLoginName(String loginName)
	{
		this.loginName = loginName;
	}
	public String getUserType()
	{
		return userType;
	}
	public void setUserType(String userType)
	{
		this.userType = userType;
	}
	public List<FunctionsEnum> getFunctions()
	{
		return functions;
	}
	public void setFunctions(List<FunctionsEnum> functions)
	{
		this.functions = functions;
	}
	
	public boolean haveFunction(String code) {
		for (FunctionsEnum functionsEnum : functions) {
			if(functionsEnum.getCode().equals(code))
				return true;
		}
		return false;
	}
	
	/**
	 * 是否拥有权限
	 * 
	 * @param fe
	 * @return
	 */
	public boolean haveFunction(FunctionsEnum fe) {
		return haveFunction(fe.getCode());
	}

	/**
	 * 添加权限
	 * @param functionsEnum
	 */
	public void addFunction(FunctionsEnum functionsEnum)
	{
		functions.add(functionsEnum);
	}
	
	public UserAgent riseUp(String appId, String name, String userType, List<String> permissionCodes) {
		this.loginName = name;
		this.userType = userType;
		this.appId = appId;
		this.functions = FunctionsEnum.getFunctions(permissionCodes);
		return this;
	}
	
}
